package com.jingxi.portal.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.jingxi.common.pojo.JingXiResult;
import com.jingxi.common.util.HttpClientUtil;
import com.jingxi.model.TbUser;

@Service
public class UserServiceImpl implements UserService {

	@Value("${SSO_BASE_URL}")
	public String SSO_BASE_URL;

	@Value("${SSO_USER_TOKEN}")
	public String SSO_USER_TOKEN;

	@Value("${SSO_PAGE_LOGIN}")
	public String SSO_PAGE_LOGIN;

	@Override
	public TbUser getUserByToken(String token) {
		try {
			String json = HttpClientUtil.doGet(SSO_BASE_URL + SSO_USER_TOKEN + token);
			System.out.println(json + "-----------");
			JingXiResult result = JingXiResult.formatToPojo(json, TbUser.class);
			if (result != null) {
				if (result.getStatus() == 200) {
					return (TbUser) result.getData();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

}
